from flask import Flask,render_template,request,escape
# import vsearch


app=Flask(__name__)

def log_request(req:"Flask_requset",res:str):
	with open("zongshu.log","a") as log:
		print(req.form,req.remote_addr,req.user_agent,res,file=log,sep='|')

@app.route("/")
def Hello():
	return "Hello!Welcome to the student registration system."

@app.route("/luru")
def hello_toupiao():
	return render_template("luru.html",the_title="Add the grade here.")

@app.route("/jieguo",methods=["POST"])
def hello_jieguo():
	shuxue = request.form["shuxue"]
	yuwen = request.form["yuwen"]
	yingyu = request.form["yingyu"]
	results = float(shuxue) + float(yuwen) + float(yingyu)
	return render_template('jieguo.html',the_jieguo=results)

@app.route("/zongshu")
def hello_zongshu():
	with open("zongshu.log","r") as log:
		contents = []
		for item in log:
			contents.append([])
			for i in item.split("|"):
				contents[-1].append(escape(i))

	log_title = ["名字","数学","语文","英语","总分"]
	return render_template("zongshu.html",the_data=contents,the_log_title=log_title)

if __name__ == '__main__':
	app.run(debug=True)